import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MouseInfo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;


public class Intro_Panel extends JPanel  implements MouseListener, MouseMotionListener, ActionListener {
	
	private PanelListener listener;
	
	//1920
	private int width=0;
	//1080
	private int height=0;
	
	private Image[] imageList = new Image[11];
	
	private boolean moving=false;
	
	private Timer timer;
	
	private int position=0;
	private boolean rise=true;
	
	public Intro_Panel(int width, int height){
		
		this.width=width;
		this.height=height;
		
		imageList[0]=new ImageIcon(getClass().getResource("images/intro/background.png")).getImage();
		imageList[1]=new ImageIcon(getClass().getResource("images/intro/00.png")).getImage();
		imageList[2]=new ImageIcon(getClass().getResource("images/intro/01.png")).getImage();
		imageList[3]=new ImageIcon(getClass().getResource("images/intro/02.png")).getImage();
		imageList[4]=new ImageIcon(getClass().getResource("images/intro/03.png")).getImage();
		imageList[5]=new ImageIcon(getClass().getResource("images/intro/04.png")).getImage();
		imageList[6]=new ImageIcon(getClass().getResource("images/intro/05.png")).getImage();
		imageList[7]=new ImageIcon(getClass().getResource("images/intro/06.png")).getImage();
		imageList[8]=new ImageIcon(getClass().getResource("images/intro/07.png")).getImage();
		imageList[9]=new ImageIcon(getClass().getResource("images/intro/08.png")).getImage();
		imageList[10]=new ImageIcon(getClass().getResource("images/intro/09.png")).getImage();
		
		addMouseListener(this);
		addMouseMotionListener(this);
	  	Dimension size = new Dimension(width, height);
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		setLayout(null);
		
		timer = new Timer(50, this);
		timer.start();
	}
	  

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
		//background
		g.drawImage(imageList[0], 0, 0, null);
		
		//message
		//799, 740
		g.drawImage(imageList[1+position], 799, 750, null);
		
	}
	
	public void mousePressed(MouseEvent e) {
		
    }

    public void mouseReleased(MouseEvent e) {
    	if(!moving){
    		timer.stop();
        	listener.onForward();
        	moving=true;
    	}
    	this.repaint();
    }
    
    public void mouseEntered(MouseEvent e) {
       
    }

    public void mouseExited(MouseEvent e) {
       
    }

    public void mouseClicked(MouseEvent e) {
    	
    }
    
    public void mouseMoved(MouseEvent e) {
        
    	
    }
    
    public void mouseDragged(MouseEvent e) {
        
    	
    }
    
    public void setPanelListener(PanelListener listener){
    	this.listener=listener;
    }
    
    
    public void actionPerformed(ActionEvent e) {
    	if(rise){
    		++position;
    		if(position>9){
    			position=9;
    			rise=!rise;
    		}
    	}else{
    		--position;
    		if(position<0){
    			position=0;
    			rise=!rise;
    		}
    	}
    	this.repaint();
    }
}
